
package com.crv.ci.action;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crv.common.domain.view.BizData4Page;
import com.crv.ci.model.AgentTelnet;
import com.crv.ci.service.IAgentTelnetService;
import com.crv.common.utils.IdGenerator;
import com.crv.common.utils.JsonResult;
import com.crv.common.utils.PageParam;
import com.crv.common.utils.Constants;

@Controller
public class AgentTelnetAction extends AbstractAdminController<IAgentTelnetService>{

    @Autowired
    private IAgentTelnetService agentTelnetService;
    
    @RequestMapping(value="/agenttelnet/list")
    public String list(AgentTelnet agentTelnet,ModelMap model,PageParam pageParam,HttpServletRequest request,HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(agentTelnet); 	
    	BizData4Page<AgentTelnet> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("agentTelnet", agentTelnet);
    	return "/module/agenttelnet/list";
    }    
    
    @RequestMapping(value="/agenttelnet/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("agentTelnet", new AgentTelnet());
        return "module/agenttelnet/edit";
    }    
    
    @RequestMapping(value="/agenttelnet/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	AgentTelnet agentTelnet = agentTelnetService.fetch(id);
    	model.addAttribute("agentTelnet", agentTelnet);
        return "module/agenttelnet/edit";
    }    
    
    @RequestMapping(value="/agenttelnet/save")
    @ResponseBody
    public String save(HttpServletRequest request,AgentTelnet agentTelnet){
		boolean isAddNew = StringUtils.isBlank(agentTelnet.getId())?true:false;
		if(isAddNew)
		{
			agentTelnet.setId(IdGenerator.createNewId());
			agentTelnetService.add(agentTelnet);
		}
		else
		{
			agentTelnetService.update(agentTelnet);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/agenttelnet/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	agentTelnetService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(AgentTelnet agentTelnet)
    {
    	Map<String, Object> conditions = new HashMap();
    	
		conditions.put("telnetId", agentTelnet.getTelnetId());		
		conditions.put("agentId", agentTelnet.getAgentId());		
		conditions.put("createDate", agentTelnet.getCreateDate());		
    	return conditions;
    }

    @Override
    protected IAgentTelnetService getMainService() {
        return agentTelnetService;
    }

    @Override
    protected String getMainObjName() {
        return "agenttelnet";
    }

    @Override
    protected String getViewTitle() {
        return "agenttelnet";
    }
}
